package com.example.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2024-03-02
 * Time: 17:13
 */

@Configuration
@EnableWebMvc
@ComponentScan("com.example")
public class MVCConfig implements WebMvcConfigurer {

    // 配置视图解析器
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        // 通过 registry 快速添加前后缀
        registry.jsp("/WEB-INF/views/", ".jsp");

    }


    // 开启静态资源查找
    // 1. dispatcherServlet 先去 handlerMapper 中找对应的 handler
    // 2. 找不到，再去寻找静态资源
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();// 开启该功能
    }
}
